package android.slc.appbase.repository.local.config;


import android.slc.appbase.repository.local.DbCd;

public class AppConfig {
    private static class Holder {
        private static final AppConfig INSTANCE = new AppConfig();
    }

    public static AppConfig getInstance() {
        return Holder.INSTANCE;
    }

    public static void init(int versionCode, String versionName, boolean isRelease) {
        if (appConfigIsInit) {
            return;
        }
        appConfigIsInit = true;
        getInstance().versionCode = versionCode;
        getInstance().versionName = versionName;
        getInstance().isRelease = isRelease;
        getInstance().db.putIfAbsent("versionCode", getInstance().versionCode, false)
                .putIfAbsent("versionName", getInstance().versionName, false)
                .putIfAbsent("isRelease", getInstance().isRelease, false)
                .putIfAbsent("mockMode", false, true);
    }

    private int versionCode;
    private String versionName;
    private boolean isRelease = true;
    private static boolean appConfigIsInit = false;
    private final DbCd db;

    private AppConfig() {
        db = new DbCd("app_config");
    }

    public static int getVersionCode() {
        return getInstance().versionCode;
    }

    public static String getVersionName() {
        return getInstance().versionName;
    }

    public static boolean isRelease() {
        return getInstance().isRelease;
    }

    public static boolean isMockMode() {
        return getInstance().db.getBoolean("mockMode");
    }

    public static void setMockMoe(boolean mockMode) {
        getInstance().db.putValue("mockMode", mockMode);
    }
}
